package org.travel.api.travel.controller.wmh.order;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.travel.api.travel.controller.wmh.user.user;
import org.travel.api.travel.dao.wmh.order.flightsOrderDao;
import org.travel.api.travel.dao.wmh.order.orderInfoDao;
import org.travel.api.travel.pojo.Flightsorder;
import org.travel.api.travel.pojo.Orderinfo;
import org.travel.api.travel.pojo.User;
import org.travel.api.travel.utils.MySpecification;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/Order")
@CrossOrigin(value = "*")
public class order {
        @Autowired
        private flightsOrderDao flightsOrderDao;
        @Autowired
        private orderInfoDao orderInfoDao;

        @RequestMapping("/getall")
        public Map<String,Object> getall(Flightsorder flightsorder, Orderinfo orderinfo)throws Exception{
            Map<String,Object> map = new HashMap<>();
            List<Flightsorder> flightsorders =flightsOrderDao.findAll(new MySpecification<>().and(MySpecification.Cnd.eq("dictionaries.dicId",flightsorder.getDictionaries().getDicId())).and(MySpecification.Cnd.eq("user.id", flightsorder.getUser().getId())));
            List<Orderinfo> orderinfos =orderInfoDao.findAll(new MySpecification<>().and(MySpecification.Cnd.eq("dictionaries.dicId",orderinfo.getDictionaries().getDicId())).and(MySpecification.Cnd.eq("user.id",orderinfo.getUser().getId())));

            map.put("flightsorders",flightsorders);
            map.put("orderinfos",orderinfos);

            return map;
        }
}
